import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { Stock, StockService } from '../stock.service';
import { FormControl } from '@angular/forms';
import { debounceTime } from "rxjs/operators"

@Component({
  selector: 'app-stock-manage',
  templateUrl: './stock-manage.component.html',
  styleUrls: ['./stock-manage.component.css']
})
export class StockManageComponent implements OnInit {

  // 表格数据
  private stocks: Array<Stock>;
  private nameFilter: FormControl = new FormControl();
  private keywores:string;
  constructor(public router: Router, private stockService: StockService) { }

  ngOnInit() {
    this.stocks = this.stockService.getStocks();
    this.nameFilter.valueChanges
    .pipe(debounceTime(500))
    .subscribe(value => this.keywores = value)
  }

  create() {
    this.router.navigateByUrl('/stock/0')
  }

  uptate(stock: Stock) {
    this.router.navigateByUrl(`/stock/${stock.id}`)
  }
}
